using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Mail;
using Excuse.Models;
using Resources;

namespace Excuse.Business
{
    public class EmailManager
    {
        const string host = "smtp.gmail.com";
        const int port = 587;
        const string userAccount = "snakzbenjy@gmail.com";
        const string passwordAccount = "Supinf03";
        //const string host = "smtp.1and1.com";
        //const int port = 25;
        //const string userAccount = "registration@isecretpage.com";
        //const string passwordAccount = "1Secret";

        public static bool Send(EmailContact from, ICollection<EmailContact> to, string subject, string bodyHtml)
        {
            try
            {
                if (from == null) // par defaut
                {
                    from = new EmailContact()
                               {
                                   DisplayName = ApplicationLabels.iSecretPageLabel,
                                   Email = userAccount//"no-reply@isecretpage.com"
                               };
                }

                MailMessage m = new MailMessage();
                SmtpClient sc = new SmtpClient();

                // Configuration
                sc.Host = host;
                sc.UseDefaultCredentials = false;
                sc.Port = port;
                sc.Credentials = new
                System.Net.NetworkCredential(userAccount, passwordAccount);
                sc.EnableSsl = true;

                m.From = new MailAddress(from.Email, from.DisplayName);
                foreach (var email in to)
                {
                    m.To.Add(new MailAddress(email.Email, email.DisplayName));
                }

                m.Subject = subject;
                m.IsBodyHtml = true;
                m.Body = bodyHtml;

                sc.Send(m);



                ////create the mail message
                //MailMessage mail = new MailMessage();
                ////set the FROM address
                //mail.From = new MailAddress("registration@isecretpage.com");
                ////set the RECIPIENTS
                //mail.To.Add("thomabenjamin@gmail.com");
                ////enter a SUBJECT
                //mail.Subject = "Set the subject of the mail here.";
                ////Enter the message BODY
                //mail.Body = "Enter text for the e-mail here.";
                ////set the mail server (default should be smtp.1and1.com)
                //SmtpClient smtp = new SmtpClient("smtp.1and1.com");
                ////Enter your full e-mail address and password
                //smtp.Credentials = new NetworkCredential("registration@isecretpage.com", "1Secret");
                ////send the message 
                //smtp.Send(mail);




                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
            
        }
    }
}
